#ifndef CALCULATOR_H
#define CALCULATOR_H

#include <QWidget>
#include<QStack>
#include<QMessageBox>
#include<QCloseEvent>

namespace Ui {
class Calculator;
}

class Calculator : public QWidget
{
    Q_OBJECT

public:
    explicit Calculator(QWidget *parent = nullptr);
    ~Calculator();


private slots:
    void on_oneButton_clicked();

    void on_twoButton_clicked();

    void on_threeButton_clicked();

    void on_fourButton_clicked();

    void on_fiveButton_clicked();

    void on_sixButton_clicked();

    void on_sevenButton_clicked();

    void on_eightButton_clicked();

    void on_nineButton_clicked();

    void on_zeroButton_clicked();

    void on_leftButton_clicked();

    void on_rightButton_clicked();

    void on_addButton_clicked();

    void on_subButton_clicked();

    void on_multButton_clicked();

    void on_divButton_clicked();

    void on_equalButton_clicked();

    void on_clearButton_clicked();

    void on_deltButton_clicked();

    void on_backButton_clicked();
protected:
    void closeEvent(QCloseEvent *event) override {
        // 发出信号或其他操作来通知Widget
        // 或者如果Widget是parent，可以直接调用它的show方法
        if (QWidget *parentWidget = this->parentWidget()) {
            if (parentWidget->inherits("Widget")) { // 确保parent是Widget类型
                parentWidget->show();
            }
        }
        event->accept(); // 允许窗口关闭
    };
signals:
    void finished();
private:
    Ui::Calculator *ui;
    QString expression;
    int Priority(char ch);
};

#endif // CALCULATOR_H
